'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), controller.user.login);
  } else {
    router.post('/api/user/login', controller.user.login);
  }
  // 会员
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);
  // role
  router.get('/api/role/list', controller.role.allList);
  router.resources('role', '/api/role', controller.role);

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);

  // notice
  router.get('/api/legalHubDetail/list', controller.legalHubDetail.allList);
  router.resources('legalHubDetail', '/api/legalHubDetail', controller.legalHubDetail);
    // comment
    router.get('/api/comment/list', controller.comment.allList);
    router.resources('comment', '/api/comment', controller.comment);
  // practice
  router.get('/api/practice/list', controller.practice.allList);
  router.resources('practice', '/api/practice', controller.practice);
    // fun
    router.get('/api/fun/list', controller.fun.allList);
    router.resources('fun', '/api/fun', controller.fun);
    // chat
    router.get('/api/chat/list', controller.chat.allList);
    router.resources('chat', '/api/chat', controller.chat);
  // collect
  router.get('/api/collect/list', controller.collect.allList);
  router.resources('collect', '/api/collect', controller.collect);
  // like
  router.get('/api/like/list', controller.like.allList);
  router.resources('like', '/api/like', controller.like);
};
